package top.huhuiyu.javabasic.javabasictemplate.entity;

import java.io.Serializable;

public class Page implements Serializable {
    private static final long serialVersionUID = 1L;
    private int pageNumber = 1; // 当前页
    private int pageSize = 10; // 每页显示的记录数
    private int total = 0; // 总记录数

    public Page() {
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        if (pageNumber < 0) {
            return;
        }
        this.pageNumber = pageNumber;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        if (pageSize < 1) {
            return;
        }
        this.pageSize = pageSize;
    }

    public int getTotal() {

        return total;
    }

    public void setTotal(int total) {
        if (total < 0) {
            return;
        }
        this.total = total;
    }

    public int getPageCount() {
        if (total <= 0) {
            return 0;
        }
        int count = total / pageSize;
        if (total % pageSize > 0) {
            count++;
        }
        return count;
    }

    public int getStart() {
        if (pageNumber <= 0) {
            return 0;
        }
        return (pageNumber - 1) * pageSize;
    }

    @Override
    public String toString() {
        return "Page{" + "pageNumber=" + pageNumber + ", pageSize=" + pageSize + ", total=" + total + '}';
    }
}
